import operator

list = ['Google', 'Taobao', 1990, 2022]
print("list2v1:", list[2])

list[2] = 1996  # 更新列表元素
print("list2v2:", list[2])
print(list)

del list[3]  # 删除列表元素
print(list)

'''列表运算符'''
print(len([1, 2, 3]))
print([1, 2, 3] + [4, 5, 6])
print(['hi'] * 4)
print(3 in [1, 2, 3])
for x in [1, 2, 3]: print(x, end="")

squares = [1, 2, 3, 4, 5]
squares += [10, 20, 30, 40, 50]
print(squares)

'''列表嵌套'''
a = ['a', 'b', 'c']
b = [1, 2, 3]
x = [a, b]
print(x)
print(x[0])
print(x[0][1])  # 取x下标为0元素后再取a里面下标为1的元素

'''导入 operator 模块'''
a = [1, 2]
b = [2, 1]
c = [1, 2]
print(f'判断两个元素是否相等:{operator.eq(a, b)}')
print("判断两个元素是否相等:", operator.eq(a, c))

'''列表的内置函数'''
tinylist = [1, 10, 100]
list = [100, 1000, 1990, 2022, True, False, 100]
print(max(list))
print(len(list))
print(min(list))
seq = (10, 100, True)
print(type(seq))
# 将元组转换成List: print(list(seq))
print(list.count(100))
print(list.index(2022))

'''列表的内置方法'''
list.append(1023)
print(list)
list.extend(tinylist)
print(list)
list.insert(2, 666)
print(list)
list.remove(False)
print(list)
list.reverse()
print(list)
list.pop(-2)  # 移除列表中指定下标位置的元素
print(list)
# list.sort(key=None,reverse=False) # 按默认规则（升序）排列
list.sort()  # 按默认规则（升序）排列
print(list)
# list.clear()
list_new = list.copy()  # 复制列表
print(f'list_new={list_new}')
